package com.c.yinyuezhushou.Dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.c.yinyuezhushou.Interface.MyInterface;
import com.c.yinyuezhushou.R;

import org.json.JSONException;

public class MyDialog extends AlertDialog {
    private boolean cancelable;
    private String title;
    private MyInterface myInterface;
    private String content;
    public MyDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener, String title,String content, MyInterface myInterface) {
        super(context, cancelable, cancelListener);
        this.cancelable = cancelable;
        this.title = title;
        this.content = content;
        this.myInterface = myInterface;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_my);
        setCancelable(cancelable);
        Window window = getWindow();
        window.setBackgroundDrawableResource(R.color.touming);
        WindowManager.LayoutParams params = window.getAttributes();

        params.gravity = Gravity.CENTER;

        window.setAttributes(params);

        ((TextView)findViewById(R.id.dm_text1)).setText(title);
        if (content!=null){
            ((TextView)findViewById(R.id.dm_text2)).setText(content);
        }
        findViewById(R.id.dm_button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myInterface.con();
                MyDialog.this.dismiss();
            }
        });
        findViewById(R.id.dm_button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    myInterface.can();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                MyDialog.this.dismiss();
            }
        });
    }
}
